﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Windows.Forms;

namespace ChimneySim
{
    class World
    {
        private float temp0, temp1;
        public float pressure, gravity;
        float worldHeight = 100;
        public Vector3 windSpeed;
        
        MainForm form;

        public World(MainForm form)
        {
            this.form = form;

            windSpeed = Vector3.Zero;
            Refresh();
        }

        public void Refresh()
        {
            temp0 = (float)form.temp0NB.Value;
            temp1 = (float)form.temp1NB.Value;
            pressure = (float)form.pressureNB.Value;
            gravity = (float)form.GravNB.Value;
        }

        public float TemperatureOnHeight(float height)
        {
            return (temp1 - temp0)/worldHeight * height + temp0;
        }

        public float RoOnHeight(float height)
        {
            Refresh();
            return pressure / ((float)8.3144 * TemperatureOnHeight(height));
        }

        public float ActivePressureOnHeight(float height)
        {
            Refresh();
            return (RoOnHeight(worldHeight) - RoOnHeight(height)) * worldHeight * gravity;
        }

        public float ActiveForceOnHeight(float height)
        {
            Refresh();
            //float S = Math.Abs(chimneyRight.Min.X - chimneyLeft.Max.X) * Math.Abs(chimneyLeft.Max.Z - chimneyRight.Min.Z);

            return ActivePressureOnHeight(height);// * S;
        }
    }
}
